home *** CD-ROM | disk | FTP | other *** search
/ Practical Internet Web Designer 86 / PIWD86.iso / pc / contents / dreamweaver / software / dwmx2004.exe / Disk1 / data1.cab / Configuration_En / Commands / Edit User Profile.js < prev    next >
Encoding:
JavaScript  |  2003-09-05  |  8.4 KB  |  234 lines

  1. // Copyright 2001, 2002, 2003 Macromedia, Inc. All rights reserved.
  2. //--------- globals -----------
  3.  
  4. var UI;  //global object to hold class instance
  5.  
  6.  
  7. //--------- API -----------
  8.  
  9. function commandButtons()
  10. {
  11.    return new Array( "OK",     "UI.okClicked()");
  12. }
  13.  
  14. //--------- class constructor -----------
  15.  
  16. function UiManager()
  17. {
  18.   this.basePath = dw.getConfigurationPath() + "/";
  19.  
  20.   //Locate all UI elements
  21.   with (document.theForm)
  22.   {
  23.     this.persona          = persona;
  24.  
  25.     this.contributorName  = contributorName;
  26.     this.contributorEmail = contributorEmail;
  27.  
  28.     this.reviewEnabled    = reviewEnabled;
  29.     this.reviewer      = reviewer;
  30.  
  31.     this.friendlyRootURL  = friendlyRootURL;
  32.     this.siteRoot         = siteRoot;
  33.     this.homePage         = homePage;
  34.  
  35.     this.sharedSiteRoot   = sharedSiteRoot;
  36.     this.shadowRoot       = shadowRoot;
  37.     this.contributorPrivateSiteRoot = contributorPrivateSiteRoot;
  38.     this.reviewerPrivateSiteRoot    = reviewerPrivateSiteRoot;
  39.   }
  40.  
  41.   //read design notes to determine which persona we're using, and select in menu
  42.   var profileObj = openProfile();
  43.   this.persona.selectedIndex = parseInt(MMNotes.get(profileObj, "persona"));
  44.   closeProfile(profileObj);
  45.  
  46.   this.initializeUI();
  47. }
  48.  
  49.  
  50. //---------- methods -----------
  51.  
  52. UiManager.prototype.initializeUI        = UiManager_initializeUI;
  53. UiManager.prototype.changePersona       = UiManager_changePersona;
  54. UiManager.prototype.cancelClicked       = UiManager_cancelClicked;
  55. UiManager.prototype.okClicked           = UiManager_okClicked;
  56. UiManager.prototype.allowReviewSettings = UiManager_allowReviewSettings;
  57.  
  58.  
  59. function UiManager_initializeUI()
  60. {
  61.   //Initialize form values;
  62.   this.contributorName.value  = FileStateManager.debugOnlyGetContributorName();
  63.   this.contributorEmail.value = FileStateManager.debugOnlyGetContributorEmail();
  64.  
  65.   this.reviewEnabled.checked  = FileStateManager.debugOnlyGetReviewEnabled();
  66.   this.reviewer.checked       = FileStateManager.debugOnlyGetReviewer();
  67.   this.allowReviewSettings();
  68.  
  69.   this.friendlyRootURL.value  = FileStateManager.debugOnlyGetFriendlyRootURL();
  70.   this.siteRoot.value         = stripConfigPath(FileStateManager.debugOnlyGetSiteRoot());
  71.   this.homePage.value         = stripConfigPath(FileStateManager.debugOnlyGetHomePage());
  72.  
  73.   this.sharedSiteRoot.value   = stripConfigPath(FileStateManager.debugOnlyGetSharedSiteRoot());
  74.   this.shadowRoot.value       = stripConfigPath(FileStateManager.debugOnlyGetShadowRoot());
  75.   this.contributorPrivateSiteRoot.value = stripConfigPath(FileStateManager.debugOnlyGetContributorPrivateSiteRoot());
  76.   this.reviewerPrivateSiteRoot.value    = stripConfigPath(FileStateManager.debugOnlyGetReviewerPrivateSiteRoot());
  77. }
  78.  
  79.  
  80. function UiManager_changePersona()
  81. {
  82.   //save settings for current profile
  83.   var profileObj = openProfile();
  84.   var oldPersonaValue = MMNotes.get(profileObj, "persona");
  85.   writeProfileSettings(oldPersonaValue);
  86.   closeProfile(profileObj);
  87.  
  88.   //write new persona value to design notes, and read new values
  89.   switchToPersona(this.persona.selectedIndex);
  90.  
  91.   //load new values into UI
  92.   this.initializeUI();
  93. }
  94.  
  95.  
  96. function UiManager_cancelClicked()
  97. {
  98.   window.close();
  99. }
  100.  
  101.  
  102. function UiManager_okClicked()
  103. {
  104.   FileStateManager.debugOnlySetContributorName(this.contributorName.value);
  105.   FileStateManager.debugOnlySetContributorEmail(this.contributorEmail.value);
  106.  
  107.   FileStateManager.debugOnlySetReviewEnabled(this.reviewEnabled.checked);
  108.   FileStateManager.debugOnlySetReviewer(this.reviewer.checked);
  109.  
  110.   FileStateManager.debugOnlySetFriendlyRootURL(this.friendlyRootURL.value);
  111.   FileStateManager.debugOnlySetSiteRoot(this.basePath + this.siteRoot.value);
  112.   FileStateManager.debugOnlySetHomePage(this.basePath + this.homePage.value);
  113.  
  114.   FileStateManager.debugOnlySetSharedSiteRoot(this.basePath + this.sharedSiteRoot.value);
  115.   FileStateManager.debugOnlySetShadowRoot(this.basePath + this.shadowRoot.value);
  116.   FileStateManager.debugOnlySetContributorPrivateSiteRoot(this.basePath + this.contributorPrivateSiteRoot.value);
  117.   FileStateManager.debugOnlySetReviewerPrivateSiteRoot(this.basePath + this.reviewerPrivateSiteRoot.value);
  118.  
  119.   dw.getDocumentDOM().refreshPanes();
  120.   writeProfileSettings(this.persona.selectedIndex);
  121.  
  122.   window.close();
  123. }
  124.  
  125.  
  126. function UiManager_allowReviewSettings()
  127. {
  128.   this.reviewer.setAttribute("disabled", !this.reviewEnabled.checked);
  129. }
  130.  
  131.  
  132.  
  133. //---------- local functions -----------
  134.  
  135. //If path starts with current config path, strip it off before writing
  136.  
  137. function stripConfigPath(path)
  138. {
  139.   var basePath = dw.getConfigurationPath();
  140.   if (path.indexOf(basePath) == 0) {
  141.     path = path.substring(basePath.length+1);
  142.   }
  143.   return path;
  144. }
  145.  
  146.  
  147. //If path is stored as relative (not file: or http:), precede with full local path.
  148.  
  149. function makeAbsPath(path)
  150. {
  151.   var basePath = dw.getConfigurationPath();
  152.   if (path.indexOf("file:") != 0 && path.indexOf("http:") != 0) {
  153.     path = basePath + "/" + path;
  154.   }
  155.   return path;
  156. }
  157.  
  158.  
  159. function openProfile() {
  160.   var profileLoc = dw.getConfigurationPath() + "/Startup/ContributorInit.htm";
  161.   return MMNotes.open(profileLoc, true);  //open, or create metafile
  162. }
  163.  
  164.  
  165. function closeProfile(profileObj) {
  166.   MMNotes.close(profileObj);
  167. }
  168.  
  169. //First writes the persona value (0, 1, or 2), then sets the appropriate design notes
  170. //to the current FileStateManager values.
  171.  
  172. function writeProfileSettings(p) {  //passed a persona value, appends to key names
  173.   var profileObj = openProfile();
  174.  
  175.   MMNotes.set(profileObj, "persona", p);
  176.  
  177.   MMNotes.set(profileObj, "contributorName"+p, FileStateManager.debugOnlyGetContributorName());
  178.   MMNotes.set(profileObj, "contributorEmail"+p, FileStateManager.debugOnlyGetContributorEmail());
  179.  
  180.   MMNotes.set(profileObj, "reviewEnabled"+p, FileStateManager.debugOnlyGetReviewEnabled());
  181.   MMNotes.set(profileObj, "reviewer"+p, FileStateManager.debugOnlyGetReviewer());
  182.  
  183.   MMNotes.set(profileObj, "friendlyRootURL"+p, FileStateManager.debugOnlyGetFriendlyRootURL());
  184.   MMNotes.set(profileObj, "siteRoot"+p, stripConfigPath(FileStateManager.debugOnlyGetSiteRoot()));
  185.   MMNotes.set(profileObj, "homePage"+p, stripConfigPath(FileStateManager.debugOnlyGetHomePage()));
  186.  
  187.   MMNotes.set(profileObj, "sharedSiteRoot"+p, stripConfigPath(FileStateManager.debugOnlyGetSharedSiteRoot()));
  188.   MMNotes.set(profileObj, "shadowRoot"+p, stripConfigPath(FileStateManager.debugOnlyGetShadowRoot()));
  189.   MMNotes.set(profileObj, "contributorPrivateSiteRoot"+p, stripConfigPath(FileStateManager.debugOnlyGetContributorPrivateSiteRoot()));
  190.   MMNotes.set(profileObj, "reviewerPrivateSiteRoot"+p, stripConfigPath(FileStateManager.debugOnlyGetReviewerPrivateSiteRoot()));
  191.  
  192.   closeProfile(profileObj);
  193. }
  194.  
  195.  
  196. //First reads persona value (0, 1, or 2), then reads the appropriate set of design notes
  197. //and sets the FileStateManager settings to those values.
  198.  
  199. function readProfileSettings() {
  200.   var profileObj = openProfile();
  201.  
  202.   var p = MMNotes.get(profileObj, "persona");
  203.  
  204.   FileStateManager.debugOnlySetContributorName(MMNotes.get(profileObj, "contributorName"+p));
  205.   FileStateManager.debugOnlySetContributorEmail(MMNotes.get(profileObj, "contributorEmail"+p));
  206.  
  207.   FileStateManager.debugOnlySetReviewEnabled(MMNotes.get(profileObj, "reviewEnabled"+p) == "true");
  208.   FileStateManager.debugOnlySetReviewer(MMNotes.get(profileObj, "reviewer"+p) == "true");
  209.  
  210.   FileStateManager.debugOnlySetFriendlyRootURL(MMNotes.get(profileObj, "friendlyRootURL"+p));
  211.   FileStateManager.debugOnlySetSiteRoot(makeAbsPath(MMNotes.get(profileObj, "siteRoot"+p)));
  212.   FileStateManager.debugOnlySetHomePage(makeAbsPath(MMNotes.get(profileObj, "homePage"+p)));
  213.  
  214.   FileStateManager.debugOnlySetSharedSiteRoot(makeAbsPath(MMNotes.get(profileObj, "sharedSiteRoot"+p)));
  215.   FileStateManager.debugOnlySetShadowRoot(makeAbsPath(MMNotes.get(profileObj, "shadowRoot"+p)));
  216.   FileStateManager.debugOnlySetContributorPrivateSiteRoot(makeAbsPath(MMNotes.get(profileObj, "contributorPrivateSiteRoot"+p)));
  217.   FileStateManager.debugOnlySetReviewerPrivateSiteRoot(makeAbsPath(MMNotes.get(profileObj, "reviewerPrivateSiteRoot"+p)));
  218.  
  219.   closeProfile(profileObj);
  220. }
  221.  
  222.  
  223. //Given a persona number (0, 1, or 2), loads that persona
  224.  
  225. function switchToPersona(personaNum)
  226. {
  227.   //write new persona value to design notes, and read new values
  228.   var profileObj = openProfile();
  229.   MMNotes.set(profileObj, "persona", personaNum);
  230.   closeProfile(profileObj);
  231.   readProfileSettings();
  232.   dw.getDocumentDOM().refreshPanes();
  233. }
  234.